//! 定义了武将势力数据

/// 武将势力
#[derive(Debug, Clone, PartialEq)]
pub enum Power {
    /// 未知势力，一般表示出错
    ///
    /// TIP: 不是神势力
    Unknown,

    /// 魏势力
    WEI,

    /// 蜀势力
    SHU,

    /// 吴势力
    WU,

    /// 群势力
    QUN,

    /// 神势力
    SHEN,
}

impl Default for Power {
    fn default() -> Self {
        Self::Unknown
    }
}

impl std::fmt::Display for Power {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Self::WEI => "魏",
                Self::SHU => "蜀",
                Self::WU => "吴",
                Self::QUN => "群",
                Self::SHEN => "神",
                Self::Unknown => "Unknown",
            }
        )
    }
}

impl TryFrom<&str> for Power {
    type Error = crate::ParseStrError;

    fn try_from(text: &str) -> Result<Self, Self::Error> {
        match text {
            "魏" | "魏国" | "WEI" | "Wei" | "wei" | "W" | "w" => Ok(Self::WEI),

            "蜀" | "蜀国" | "SHU" | "Shu" | "shu" | "S" | "s" => Ok(Self::SHU),

            "吴" | "吴国" | "WU" | "Wu" | "wu" | "U" | "u" => Ok(Self::WU),

            "群" | "QUN" | "Qun" | "qun" | "Q" | "q" => Ok(Self::QUN),

            "神" | "SHEN" | "Shen" | "shen" | "GOD" | "God" | "G" | "g" => Ok(Self::SHEN),

            _ => Err(crate::ParseStrError::new(crate::ParseType::Power, text)),
        }
    }
}
